package com.ziki.expandable;

import java.util.List;

import com.ziki.testmodulename.R;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class ActivityExpandableAdapter extends BaseExpandableListAdapter {
    private final List<List<String>> child;
    private final Context context;
    private final List<String> group;

    public static class ExpandableListData {

    }

    public ActivityExpandableAdapter(Context context, List<String> group, List<List<String>> child) {
        this.context = context;
        this.group = group;
        this.child = child;
    }

    @Override
    public int getGroupCount() {
        return group.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return child.get(i).size();
    }

    @Override
    public Object getGroup(int i) {
        return group.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return child.get(i).get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = View.inflate(context, R.layout.listview_group, null);
            view.setTag(new GroupViewHolder(view));
        }
        GroupViewHolder groupViewholder = (GroupViewHolder) view.getTag();
        groupViewholder.listviewHeader.setText(group.get(i));
        groupViewholder.listviewCount.setText(child.get(i).size() + "");
        return view;
    }

    protected class GroupViewHolder {
        private TextView listviewHeader;
        private TextView listviewCount;

        public GroupViewHolder(View view) {
            listviewHeader = (TextView) view.findViewById(R.id.listview_header);
            listviewCount = (TextView) view.findViewById(R.id.listview_count);
        }
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = View.inflate(context, R.layout.listview_child, null);
            view.setTag(new ChildViewHolder(view));
        }
        ChildViewHolder childViewHolder = (ChildViewHolder) view.getTag();
        childViewHolder.childName.setText(child.get(i).get(i1));
        childViewHolder.childModel.setText("ss");
        return view;
    }

    protected class ChildViewHolder {
        private TextView childName;
        private TextView childModel;

        public ChildViewHolder(View view) {
            childName = (TextView) view.findViewById(R.id.child_name);
            childModel = (TextView) view.findViewById(R.id.child_model);
        }
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }
}
